home *** CD-ROM | disk | FTP | other *** search
- Path: cs.utexas.edu!not-for-mail
- From: wilson@cs.utexas.edu (Paul Wilson)
- Newsgroups: comp.lang.lisp,comp.lang.c++
- Subject: Re: Why garbage collection?
- Date: 5 Feb 1996 09:14:46 -0600
- Organization: CS Dept, University of Texas at Austin
- Message-ID: <4f56t6$7i0@jive.cs.utexas.edu>
- References: <rvillDL4v3n.I8r@netcom.com> <822848307snz@wildcard.demon.co.uk> <4eu5l9$5m9@jive.cs.utexas.edu> <823365355snz@wildcard.demon.co.uk>
- NNTP-Posting-Host: jive.cs.utexas.edu
-
- In article <823365355snz@wildcard.demon.co.uk>,
- Cyber Surfer <cyber_surfer@wildcard.demon.co.uk> wrote:
- >In article <4eu5l9$5m9@jive.cs.utexas.edu>
- > wilson@cs.utexas.edu "Paul Wilson" writes:
- >
- >Was I refering to modern GC? I'm not sure. I don't know of any books
- >on modern GC, but a book 20 years old seems to contain GC techniques
- >that many C/C++ programmers are unaware of. Even if that's the best
- >book on the subject, it could still enlighten a few programmers.
-
- True. Simple GC techniques are acceptable for a fair number of applications.
- My favorite example is scripting languages. Most scripting languages are
- so slow that the cost of GC is negligible, even if it's implemented badly
- by the standards of the state of the art. People often use reference counting
- because that's what the C++ books give examples of, when mark-sweep would
- work like a charm, and often when copying collection wouldn't be very
- hard. Reference counting works well in the sense that it wastes little
- space most of the time---getting space back immediately in most cases,
- rather than waiting until the next GC---but for a slow language implementation,
- mark sweep is just about as efficient if you crank the GC frequency up.
-
- With a simple non-generational GC, you may pay a fair amount of CPU time
- to get space back quickly, but for scripting languages that cost is still
- usually swamped by the cost of interpretation. The real cost may be in
- locality, because a simple GC touches most or all of the live data at
- each GC cycle. So you'd rather have a generational GC.
-
- And a generational GC is pretty easy to implement, too. Appel implemented
- a decent generational GC for ML in 500 lines of C code. For fast implemen-
- tations of general-purposes languages, you may want something a little
- fancier (his write barrier is probably too simple), but not much fancier.
- For a scripting language, a 500 line GC is probably plenty fast.
-
- --
- | Paul R. Wilson, Comp. Sci. Dept., U of Texas @ Austin (wilson@cs.utexas.edu)
- | Papers on memory allocators, garbage collection, memory hierarchies,
- | persistence and Scheme interpreters and compilers available via ftp from
- | ftp.cs.utexas.edu, in pub/garbage (or http://www.cs.utexas.edu/users/wilson/)
-